﻿using UnityEngine;
using System.Collections;

public class DestroyByContact : MonoBehaviour 
{
    public GameObject explosion;
    public GameObject PlayerExplosion;

    public int scoreValue;

    private GameController _GameController;

    void Start ()
    {
        GameObject GameControllerObject = GameObject.FindWithTag("GameController");
        if(GameControllerObject != null)
        {
            _GameController = GameControllerObject.GetComponent<GameController>();
        }

        if(_GameController == null)
        {
            Debug.Log("Cannot Find 'GameController' Script");
        }
    }

	void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary" || other.tag == "Enemy")
        {
            return;
        }        

        if (other.tag == "Player")
        {
            Instantiate(PlayerExplosion, other.transform.position, other.transform.rotation);
            Destroy(other.gameObject);
            _GameController.CheckState();
            _GameController.GameOver();            
        }

        if (other.gameObject.tag == "Player Bolt")
        {
            _GameController.AddScore(scoreValue);
            Instantiate(explosion, this.transform.position, this.transform.rotation);
            Destroy(other.gameObject);
            Destroy(gameObject);
        }
    }
}
